#include <iostream>
#include <list>
using namespace std;

int main()
{
	int n, m; cin >> n >> m;
	list<int> l;
	for (int i = 1; i <= n; i++) l.push_back(i);
	auto it = l.begin();
	while (l.size() > 1) {
		for (int j = 1; j < m; j++) {
			if (++it == l.end()) it = l.begin();
		}
		it = l.erase(it);
		if (it == l.end()) it = l.begin();
	}
	cout << l.front();
	return 0;
}
